package com.skycode6.dao;

import com.skycode6.bean.NewsBean;
import com.skycode6.util.DBConnection;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

public class NewsDao {
    DBConnection DBConn = new DBConnection();
    public List<NewsBean> getList(){
        Connection conn = DBConn.getConn();
        String sql = "select * from news";
        List<NewsBean> list = null;
        try {
            Statement stmt = conn.createStatement();
            ResultSet rs =  stmt.executeQuery(sql);
            while (rs.next()) {
                NewsBean newsBean = new NewsBean();
                newsBean.setNewsID(rs.getInt("NewsID"));
                newsBean.setNewsTitle(rs.getString("NewsTitle"));
                newsBean.setNewsContent(rs.getString("NewsContent"));
                newsBean.setNewsTime(rs.getString("NewsTime"));
                newsBean.setAdminName(rs.getString("AdminName"));
                list.add(newsBean);
            }
        } catch (SQLException e) { throw new RuntimeException(e);}
        return list;
    }
}
